// pages/shopping_mall/success/msg_success.js
Page({
  onLoad: function () {
    wx.getStorage({
      key: 'info',
      success: res => {
        this.setData({
          image: res.data.image,
          name: res.data.name,
        })
        wx.getStorage({
          key: 'userInfo',
          success: user => {
            // console.log(user);
            this.setData({
              username: user.data.nickName,
              url: user.data.avatarUrl
            })
            wx.cloud.callFunction({
              name: "login",
              success: open => {
                // console.log(open);
                this.setData({
                  openid: open.result.openid
                })
                // console.log(this.data.openid);
                wx.cloud.callFunction({
                  name: 'dataUp',
                  data: {
                    openid: this.data.openid,
                    name: this.data.name,
                    username: this.data.username,
                    image: this.data.image,
                    url: this.data.url,

                  },
                  success: res => {
                    console.log(res);
                  },
                  fail: err => {
                    console.error(err);
                  }
                })

              }
              //上传到数据库中
            })

          }
        })
      }
    })
  },
  reback: function (e) {
    wx.navigateBack({
      // complete: (res) => {},
      delta: 2,
      complete: res => {
        wx.removeStorage({
          key: 'info',
        })
      }
    })
  }
})